package util
{
	import SHNOPData.BaseQuery;
	
	import flash.errors.*;
	import flash.events.*;
	import flash.external.*;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.net.navigateToURL;
	import flash.utils.Timer;
	import flash.utils.setTimeout;
	
	import mx.controls.Alert;
	import mx.managers.PopUpManager;
	
	
	public class UpExcel
	{
		private static var fileRefer:FileReference = new FileReference()
		private static var urlStr:String;
		private static var type:String;
		private static var basequrey:BaseQuery = new BaseQuery();
		private static var timer:Timer;
		public static var ldWindow:loadingWindow=null;
		private static var parentWindow:*;
		public function UpExcel()
		{
		}
		
		public static function importExcel(url:String,window:*):void{
			//过滤文件
			var fileType:FileFilter = new FileFilter("Excel","*.xlsx;*.xls");
			
			var fileTypes:Array = new  Array(fileType);
			
			//导入
			urlStr=url;
			fileRefer.addEventListener(Event.SELECT,parseExcel);
			
			fileRefer.browse(fileTypes);
			parentWindow=window;
		
			
		}
		private static function parseExcel(evt:Event):void {
			var url:URLRequest=new  URLRequest(urlStr);//("../ExcelUp?loadType=parseExcel");
			fileRefer.upload(url);
			ldWindow=new loadingWindow()
			
			PopUpManager.addPopUp(ldWindow,parentWindow,true); 
			PopUpManager.centerPopUp(ldWindow);
			//定时器  获取session
			timer=new Timer(3000,0);
			timer.addEventListener(TimerEvent.TIMER, getSession);
			timer.start();
			
		}
		private static function getSession(event:TimerEvent):void{
			
			basequrey.onReceive_GetSession = onReceive_GetSession;
	
			basequrey.GetSession();
		}
		private static function onReceive_GetSession(receiveData:Object):void
		{
			if(timer!=null){
				timer.stop();
			}
			if(ldWindow!=null){
				PopUpManager.removePopUp(ldWindow);   
			}
			basequrey.onReceive_DestroySession = onReceive_DestroySession;
			basequrey.DestroySession();
			if(receiveData!=null)
			{
				Alert.show(receiveData.toString());
			}
		}
		private static function onReceive_DestroySession(receiveData:Object):void
		{
			if(receiveData!=null)
			{
				//Alert.show(receiveData.toString());
			}
		}
	}
}


